#ifndef MK_V0_24B_NAVI_STRCUTS_H
#define MK_V0_24B_NAVI_STRCUTS_H

#define INVALID         0x00
#define NEWDATA         0x01
#define PROCESSED       0x02
#include <stdint.h>
//#include <cstdint>

typedef struct
{
        int32_t Longitude;  // in 1E-7 deg
        int32_t Latitude;   // in 1E-7 deg
        int32_t Altitude;   // in mm
        uint8_t Status;// validity of data
} __attribute__((packed)) GPS_Pos_t;


typedef struct
{
        uint16_t Distance;                                   // distance to target in cm
        int16_t Bearing;                                    // course to target in deg
}__attribute__((packed)) GPS_PosDev_t;

typedef struct
{
        GPS_Pos_t Position;             // the gps position of the waypoint, see ubx.h for details
        int16_t Heading;                    // orientation, 0 no action, 1...360 fix heading, neg. = Index to POI in WP List
        uint8_t  ToleranceRadius;    // in meters, if the MK is within that range around the target, then the next target is triggered
        uint8_t  HoldTime;                   // in seconds, if the was once in the tolerance area around a WP, this time defines the delay before the next WP is triggered
        uint8_t  Event_Flag;                 // future implementation
        uint8_t  Index;              // to indentify different waypoints, workaround for bad communications PC <-> NC
        uint8_t  Type;                               // typeof Waypoint
        uint8_t  WP_EventChannelValue;  //
        uint8_t      AltitudeRate;           // rate to change the setpoint
        uint8_t  reserve[8];             // reserve
} __attribute__((packed)) Point_t;

typedef struct
{
        uint8_t Version;                        // version for compatibility (current value is 2)
        GPS_Pos_t CurrentPosition;              // see ubx.h for details
        GPS_Pos_t TargetPosition;
        GPS_PosDev_t TargetPositionDeviation;
        GPS_Pos_t HomePosition;
        GPS_PosDev_t HomePositionDeviation;
        uint8_t  WaypointIndex;                 // index of current waypoints running from 0 to WaypointNumber-1
        uint8_t  WaypointNumber;                // number of stored waypoints
        uint8_t  SatsInUse;                     // no of satellites used for position solution
        int16_t  Altimeter;                     // height according to air pressure sensor
        int16_t  Variometer;                    // climb(+) and sink(-) rate
        uint16_t FlyingTime;                    // in seconds
        uint8_t  UBat;                          // Battery Voltage in 0.1 Volts
        int16_t  GroundSpeed;                   // speed over ground in cm/s (2D)
        int16_t  Heading;                       // current flight direction in deg as angle to north
        int16_t  CompassHeading;                // current compass value
        int8_t   AngleNick;                     // current Nick angle in 1°
        int8_t   AngleRoll;                     // current Rick angle in 1°
        uint8_t  RC_Quality;                    // RC_Quality
        uint8_t  FCStatusFlags;                 // Flags from FC
        uint8_t  NCFlags;                       // Flags from NC
        uint8_t  Errorcode;                     // 0 --> okay
        uint8_t  OperatingRadius;               // current operation radius around the Home Position in m    - since 0.15b
        int16_t  TopSpeed;                      // gps verical speed in cm/s                                 - since 0.15b
        uint8_t  TargetHoldTime;                // time to stay at the current waypoint in s                 - since 0.15b
        uint8_t  FCStatusFlags2;                // StatusFlags2 (since version 5 added)
        // since 0.17
        int16_t  SetpointAltitude;              // setpoint for altitude
        uint8_t  Gas;                           // for future use
        // since 0.18
        uint16_t Current;                       // actual current in 0.1A steps
        uint16_t UsedCapacity;                  // used capacity in mAh
} __attribute__((packed)) NaviData_t;

typedef struct
{
        GPS_Pos_t Position;                          // the gps position of the waypoint, see ubx.h for details
        int16_t Heading;                                 // orientation, future implementation
        uint8_t  ToleranceRadius;                         // in meters, if the MK is within that range around the target, then the next target is triggered
        uint8_t  HoldTime;                                // in seconds, if the was once in the tolerance area around a WP, this time defines the delay before t
        uint8_t  Event_Flag;                              // future implementation
        uint8_t  Index;                                   // to indentify different waypoints, workaround for bad communications PC <-> NC
        uint8_t  reserve[11];                             // reserve
} __attribute__((packed)) Waypoint_t;


// FC STATUS FLAGS
#define FC_STATUS_MOTOR_RUN                 0x01
#define FC_STATUS_FLY                       0x02
#define FC_STATUS_CALIBRATE                 0x04
#define FC_STATUS_START                     0x08
#define FC_STATUS_EMERGENCY_LANDING         0x10
#define FC_STATUS_LOWBAT                    0x20
#define FC_STATUS_VARIO_TRIM_UP             0x40
#define FC_STATUS_VARIO_TRIM_DOWN           0x80

// FC STATUS FLAGS2
#define FC_STATUS2_CAREFREE                 0x01
#define FC_STATUS2_ALTITUDE_CONTROL         0x02


// FC ERRORS FLAGS
#define FC_ERROR0_GYRO_NICK     0x01
#define FC_ERROR0_GYRO_ROLL     0x02
#define FC_ERROR0_GYRO_YAW      0x04
#define FC_ERROR0_ACC_NICK      0x08
#define FC_ERROR0_ACC_ROLL      0x10
#define FC_ERROR0_ACC_TOP       0x20
#define FC_ERROR0_PRESSURE      0x40
#define FC_ERROR0_CAREFREE      0x80

#define FC_ERROR1_I2C           0x01
#define FC_ERROR1_BL_MISSING    0x02
#define FC_ERROR1_SPI_RX        0x04
#define FC_ERROR1_PPM           0x08
#define FC_ERROR1_MIXER         0x10
#define FC_ERROR1_RES1          0x20
#define FC_ERROR1_RES2          0x40
#define FC_ERROR1_RES3          0x80

// NC Errors
#define NCERR_FLAG_FC_COMPATIBLE                0x01
#define NCERR_FLAG_MK3MAG_COMPATIBLE            0x02
#define NCERR_FLAG_FC_COMMUNICATION             0x04
#define NCERR_FLAG_MK3MAG_COMMUNICATION         0x08
#define NCERR_FLAG_MKGPS_COMMUNICATION          0x10
#define NCERR_FLAG_BAD_COMPASS_HEADING          0x20
#define NCERR_FLAG_RC_SIGNAL_LOST               0x40
#define NCERR_FLAG_EEPROM_NOT_FOUND             0x80


#endif // MK_V0_24B_NAVI_STRCUTS_H
